<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <script>
    function Common(name,age,sex) {
      this.name = name;
      this.age = age;
      this.sex = sex;
    }
    function Student(aihao) {
      this.aihao = aihao;
    }
    function Teacher(fangx) {
      this.fangx = fangx;
    }
    // for...in..原型继承
      // 原型对象，可以将自己的实例和方法继承给将来的实例对象使用
      Student.prototype = new Common("xxx",20,"man");
      // 同样会丢失原constructor的指向,需要手动指回
    Student.prototype.constructor = Student;
      Teacher.prototype = new Common("xxx",20,"man");
      //生成实例
      var s1 = new Student("game");
      var t1 = new Teacher("dagong");
      console.log(s1);
      console.log(s1.name);
      console.log(s1.constructor);
      console.log(t1);
      console.log(t1.name);
      console.log(t1.constructor);
  </script>
</body>
</html>